﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace vuonthieunhi.Library
{
    public class FRouter
    {
        public static string ConvertTextToNoMark(string text)
        {
            string vietChar = "á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|ó|ò|ỏ|õ|ọ|ơ|ớ|ờ|ở|ỡ|ợ|ô|ố|ồ|ổ|ỗ|ộ|ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|í|ì|ỉ|ĩ|ị|ý|ỳ|ỷ|ỹ|ỵ|đ|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ằ|Ẳ|Ẵ|Ặ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ|Ó|Ò|Ỏ|Õ|Ọ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự|Í|Ì|Ỉ|Ĩ|Ị|Ý|Ỳ|Ỷ|Ỹ|Ỵ|Đ";
            string engChar = "a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|a|e|e|e|e|e|e|e|e|e|e|e|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|o|u|u|u|u|u|u|u|u|u|u|u|i|i|i|i|i|y|y|y|y|y|d|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|A|E|E|E|E|E|E|E|E|E|E|E|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|O|U|U|U|U|U|U|U|U|U|U|U|I|I|I|I|I|Y|Y|Y|Y|Y|D";
            string[] arrVietChar = vietChar.Split('|');
            string[] arrEngChar = engChar.Split('|');
            string result = string.Empty;
            for (int i = 0; i < arrVietChar.Length; i++)
            {
                text = text.Replace(arrVietChar[i], arrEngChar[i]);
            }
            string pattern = @"[\s!@#$%^*()_+{}:<>?/]";
            string replacement = "-";
            text = Regex.Replace(text, pattern, replacement);
            text = Regex.Replace(text, "&", "a");
            text = Regex.Replace(text, @"-{2,}", "-");
            text = text.TrimEnd('-');
            return text.ToLower();
        }
        public static string _(string prefix)
        {
            prefix = ConvertTextToNoMark(prefix);
            return string.Format("/{0}.html", prefix);
        }
        public static string _(string prefix, string id, string name)
        {
            name = ConvertTextToNoMark(name);
            return string.Format("/{0}/{1}/{2}.html", prefix, id, name);
        }
        public static string _(string prefix, string alias)
        {
            alias = ConvertTextToNoMark(alias);
            return string.Format("/{0}/{1}.html", prefix, alias);
        }
    }
}